module.exports = (sequelize, DataTypes) => {
  const shop = sequelize.define('shop', {
    shopId: {
      type: DataTypes.STRING(50),
      primaryKey: true
    },
    name: DataTypes.STRING(50),
    avatar: DataTypes.STRING,
    description: DataTypes.STRING(200),
    country: DataTypes.STRING(20),
    province: DataTypes.STRING(20),
    city: DataTypes.STRING(20),
    detailAddress: DataTypes.STRING,
    disable: {
      type: DataTypes.BOOLEAN,
      defaultValue: false
    },
    checked: {
      type: DataTypes.INTEGER,
      defaultValue: 2, // 2 审核中 0 审核未通过 1 审核通过
      allowNull: false
    },
    clickRate: {
      type: DataTypes.INTEGER,
      defaultValue: 0, // 2 审核中 0 审核未通过 1 审核通过
      allowNull: false
    }
  })

  shop.associate = (models) => {
    shop.hasMany(models.shopAuth, {
      foreignKey: 'shopId',
      sourceKey: 'shopId',
      as: 'auths'
    })
    shop.hasMany(models.good, {
      foreignKey: 'shopId',
      sourceKey: 'shopId',
      as: 'goods'
    })
    shop.hasMany(models.kind, {
      foreignKey: 'shopId',
      sourceKey: 'shopId',
      as: 'kinds'
    })
    shop.hasMany(models.shopToken, {
      foreignKey: 'shopId',
      sourceKey: 'shopId',
      as: 'tokens'
    })
    shop.hasMany(models.checkApply, {
      foreignKey: 'shopId',
      sourceKey: 'shopId',
      as: 'checkApplys'
    })
  }
  return shop
}
